package core;

import fileoperation.FileDeletion;
import repository.Repository;

import java.io.File;
import java.io.IOException;
import gitobject.Blob;
import gitobject.Tree;

public class JitHash {
    /**
     * Init repository in your working area.
     * @param filename
     * @throws IOException
     */
    public static void hash(String filename) throws Exception {
        /* Todo: You should pass the filename in this function, and generate a hash file in your repository.
        *   Add your code here.*/
		File file = new File(filename);
		if(file.isFile()){
			System.out.printf("File: %s hashed.\n", filename);
			Blob bl = new Blob(file);
			System.out.printf("100644 Blob " + bl.getKey());
		}
		else if(file.isDirectory()){
			System.out.printf("Directory: %s hashed.\n", filename);
			Tree tr = new Tree(file);
			System.out.printf("040000 Tree " + tr.getKey());
		}
		else throw new IOException("The path is invalid.");
    }
}
